#include <iostream>
#include <cstring>
#include "ti.h"
#include "tplate.h"
#include "txtpara.h"
#include "taxonomy_tree.h"
using namespace std;

int main(int argc, char **argv)
{
    if (argc != 5)
    {
        cout << "Usage:\n" << argv[0] <<
            " param_file training_image_file template_file taxomony_tree_file"
            << endl;
        return 0;
    }
    train_grid *ti = new train_grid;
    read_image(ti, argv[2]);
    tplate tp;
    // Read the training image to the trianing grid
    load_template(&tp, argv[3]);
    int maxscale = 1;
    ti->NR_cate = getparaINT("NR_CATE", argv[1]);
    ti->map_cate = new cate_map[maxscale];
    build_zoomed_images(1, ti);
    ALL_taxonomy_tree *all_tree = new ALL_taxonomy_tree;
    all_tree->max_scale = maxscale;
    all_tree->t_tree = new taxonomy_tree *[maxscale];
    for (int g = 0; g < maxscale; g++)
    {
        all_tree->t_tree[g] = build_taxonomy_tree(ti, &tp, g);
    }
    save_taxonomy_tree(all_tree, tp.tpsize, argv[4]);
    return 0;
}
